<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/blog/","images":"/blog/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="1. consul 集群模式1consul agent -server -data-dir&#x3D;.&#x2F;data&#x2F; -node&#x3D;s1 -bind&#x3D;192.168.217.86 -ui -rejoin -client&#x3D;0.0.0.0 -bootstrap-expect&#x3D;1 -ui  参数介绍：  -server 表示是以服务端身份启动，去掉这个参数表示 client 模式 -bind 表示绑定到哪个ip（有">
<meta property="og:type" content="article">
<meta property="og:title" content="Consul使用记录">
<meta property="og:url" content="http://littlefxc.github.io/2019/05/23/Consul%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:description" content="1. consul 集群模式1consul agent -server -data-dir&#x3D;.&#x2F;data&#x2F; -node&#x3D;s1 -bind&#x3D;192.168.217.86 -ui -rejoin -client&#x3D;0.0.0.0 -bootstrap-expect&#x3D;1 -ui  参数介绍：  -server 表示是以服务端身份启动，去掉这个参数表示 client 模式 -bind 表示绑定到哪个ip（有">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20190522164211256.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20190522164607754.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20190522162138210.png">
<meta property="article:published_time" content="2019-05-23T01:53:08.000Z">
<meta property="article:modified_time" content="2021-03-25T13:15:48.941Z">
<meta property="article:author" content="一年春又来">
<meta property="article:tag" content="consul">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20190522164211256.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70">


<link rel="canonical" href="http://littlefxc.github.io/2019/05/23/Consul%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>Consul使用记录 | 一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/blog/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/blog/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/blog/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/blog/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/blog/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-consul-%E9%9B%86%E7%BE%A4%E6%A8%A1%E5%BC%8F"><span class="nav-text">1. consul 集群模式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%BB%BA%E7%AB%8B-consul-%E9%9B%86%E7%BE%A4"><span class="nav-text">1.1. 命令行建立 consul 集群</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E6%96%B9%E5%BC%8F%E5%BB%BA%E7%AB%8B-consul-%E9%9B%86%E7%BE%A4"><span class="nav-text">1.2. 配置文件方式建立 consul 集群</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-1-%E4%B8%BA%E4%BB%80%E4%B9%88-http-%E5%9C%B0%E5%9D%80%E8%A6%81%E7%BB%91%E5%AE%9A-127-0-0-1-%EF%BC%9F"><span class="nav-text">1.2.1.  为什么 http 地址要绑定 127.0.0.1 ？</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%9F%A5%E7%9C%8B%E9%9B%86%E7%BE%A4%E7%8A%B6%E6%80%81"><span class="nav-text">2. 查看集群状态</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">184</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/05/23/Consul%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Consul使用记录
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-05-23 09:53:08" itemprop="dateCreated datePublished" datetime="2019-05-23T09:53:08+08:00">2019-05-23</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:48" itemprop="dateModified" datetime="2021-03-25T21:15:48+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/" itemprop="url" rel="index"><span itemprop="name">注册中心</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="1-consul-集群模式"><a href="#1-consul-集群模式" class="headerlink" title="1. consul 集群模式"></a>1. consul 集群模式</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul agent -server -data-dir=./data/ -node=s1 -<span class="built_in">bind</span>=192.168.217.86 -ui -rejoin -client=0.0.0.0 -bootstrap-expect=1 -ui</span><br></pre></td></tr></table></figure>

<p>参数介绍：</p>
<ul>
<li>-server 表示是以服务端身份启动，去掉这个参数表示 <code>client</code> 模式</li>
<li>-bind 表示绑定到哪个ip（有些服务器会绑定多块网卡，可以通过bind参数强制指定绑定的ip），一般是本机IP</li>
<li>-client 指定客户端访问的ip(consul有丰富的api接口，这里的客户端指浏览器或调用方)，0.0.0.0表示不限客户端ip</li>
<li>-bootstrap-expect=3 表示server集群最低节点数为3，低于这个值将工作不正常(注：类似zookeeper一样，通常集群数为奇数，方便选举，consul采用的是raft算法)</li>
<li>-data-dir 表示指定数据的存放(持久化)目录（该目录必须存在）</li>
<li>-node 表示节点在web ui中显示的名称</li>
</ul>
<p>启动成功后，终端窗口不要关闭，可以在浏览器里，访问下，类似 <a target="_blank" rel="noopener" href="http://192.168.212.73:8500/%EF%BC%8C">http://192.168.212.73:8500/，</a> 正常的话，可以正常打开web界面。</p>
<p>为了防止终端关闭后，consul退出，可以在刚才命令上，加点东西，类似：<code>nohup xxx  &gt; /dev/null 2&gt;&amp;1 &amp; </code></p>
<h3 id="1-1-命令行建立-consul-集群"><a href="#1-1-命令行建立-consul-集群" class="headerlink" title="1.1. 命令行建立 consul 集群"></a>1.1. 命令行建立 consul 集群</h3><p>服务端1：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul agent -server -bootstrap-expect=2 -data-dir=./data/ -<span class="built_in">bind</span>=192.168.217.134 -client=0.0.0.0 -node=s1 -ui</span><br></pre></td></tr></table></figure>

<p>服务端2：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul agent -server -bootstrap-expect=2 -data-dir=./data/ -<span class="built_in">bind</span>=192.168.217.72 -client=0.0.0.0 -join 192.168.217.134 -node=s2 -ui</span><br></pre></td></tr></table></figure>

<p>服务端3：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul agent -server -bootstrap-expect=2 -data-dir=./data/ -<span class="built_in">bind</span>=192.168.217.86 -client=0.0.0.0 -join 192.168.217.134 -node=s3 -ui</span><br></pre></td></tr></table></figure>

<p>客户端1：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul agent -data-dir=./data/ -<span class="built_in">bind</span>=192.168.217.87 -client=0.0.0.0 -join 192.168.217.134 -node=c1 -ui</span><br></pre></td></tr></table></figure>

<h3 id="1-2-配置文件方式建立-consul-集群"><a href="#1-2-配置文件方式建立-consul-集群" class="headerlink" title="1.2. 配置文件方式建立 consul 集群"></a>1.2. 配置文件方式建立 consul 集群</h3><p><img src="https://img-blog.csdnimg.cn/20190522164211256.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p>例：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="comment">/* 表示server集群最低节点数 */</span></span><br><span class="line">  <span class="attr">&quot;bootstrap_expect&quot;</span>: <span class="number">2</span>,</span><br><span class="line">  <span class="comment">/* 表示该节点绑定的地址, 默认0.0.0.0 */</span></span><br><span class="line">  <span class="attr">&quot;bind_addr&quot;</span>: <span class="string">&quot;192.168.217.86&quot;</span>,</span><br><span class="line">  <span class="comment">/* 访问该节点的地址, 默认127.0.0.1*/</span></span><br><span class="line">  <span class="attr">&quot;client_addr&quot;</span>: <span class="string">&quot;0.0.0.0&quot;</span>,</span><br><span class="line">  <span class="comment">/* 访问该节点的数据中心*/</span></span><br><span class="line">  <span class="attr">&quot;datacenter&quot;</span>: <span class="string">&quot;data-center-1&quot;</span>,</span><br><span class="line">  <span class="comment">/* 必须, 数据保存的地址*/</span></span><br><span class="line">  <span class="attr">&quot;data_dir&quot;</span>: <span class="string">&quot;/home/awifi/consul-server/data&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;addresses&quot;</span>: &#123;</span><br><span class="line">    <span class="comment">/* 表示该节点绑定的dns地址, 以空格分隔的要绑定的地址列表*/</span></span><br><span class="line">    <span class="attr">&quot;dns&quot;</span>: <span class="string">&quot;192.168.217.86&quot;</span>,</span><br><span class="line">    <span class="comment">/* 表示该节点绑定的http地址, 以空格分隔的要绑定的地址列表*/</span></span><br><span class="line">    <span class="attr">&quot;http&quot;</span>: <span class="string">&quot;192.168.217.86 127.0.0.1&quot;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/* 节点名，必须*/</span></span><br><span class="line">  <span class="attr">&quot;node_name&quot;</span>: <span class="string">&quot;server:192.168.212.73:8500&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;rejoin_after_leave&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="comment">/* 表示该节点类型是server*/</span></span><br><span class="line">  <span class="attr">&quot;server&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="comment">/* 允许在第一次尝试失败时重试连接 */</span></span><br><span class="line"><span class="attr">&quot;retry_join&quot;</span>: [</span><br><span class="line">        <span class="string">&quot;192.168.217.72&quot;</span>,</span><br><span class="line">        <span class="string">&quot;192.168.217.134&quot;</span></span><br><span class="line">    ],</span><br><span class="line">  <span class="comment">/* 表示开启web界面*/</span></span><br><span class="line">  <span class="attr">&quot;ui&quot;</span>: <span class="literal">true</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后在另一台机器上执行<br>./consul join 192.168.217.86<br>或者可以加入配置</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;start_join&quot;</span>:[],</span><br><span class="line">  <span class="attr">&quot;retry_join&quot;</span>:[]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>start_join</code>：等同于 命令行参数<code> -join</code> : 表示启动时加入的集群地址<br><code>retry_join</code>：等同于 命令行参数<code> -retry-join</code> : 允许在第一次尝试失败时重试连接，该列表可以包含IPv4，IPv6或DNS地址。</p>
<h4 id="1-2-1-为什么-http-地址要绑定-127-0-0-1-？"><a href="#1-2-1-为什么-http-地址要绑定-127-0-0-1-？" class="headerlink" title="1.2.1.  为什么 http 地址要绑定 127.0.0.1 ？"></a>1.2.1.  为什么 http 地址要绑定 127.0.0.1 ？</h4><p>如果不绑定127.0.0.1，在该服务器上就会无法使用除 ./consul agent 以外的命令，</p>
<p>例如:<br>组建集群模式的核心命令：<code>consul join 192.168.217.86</code><br>优雅的注销节点的命令：  <code>consul leave</code><br><img src="https://img-blog.csdnimg.cn/20190522164607754.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpdHRsZV9meGM=,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h2 id="2-查看集群状态"><a href="#2-查看集群状态" class="headerlink" title="2. 查看集群状态"></a>2. 查看集群状态</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">consul operator raft list-peers</span><br></pre></td></tr></table></figure>

<p> 运行结果：</p>
<p><img src="https://img-blog.csdnimg.cn/20190522162138210.png" alt="查看集群状态"></p>
<p>运行结果红色方框部分可以看出集群模式中谁是 <code>leader</code></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/consul/" rel="tag"># consul</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/blog/2019/05/23/Java%E9%9B%86%E5%90%88%E5%AD%A6%E4%B9%A0%E4%B9%8BLinkedList/" rel="prev" title="Java集合学习之LinkedList">
                  <i class="fa fa-chevron-left"></i> Java集合学习之LinkedList
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/blog/2019/06/11/linux%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" rel="next" title="linux常用命令">
                  linux常用命令 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/blog/js/utils.js"></script><script src="/blog/js/motion.js"></script><script src="/blog/js/schemes/muse.js"></script><script src="/blog/js/next-boot.js"></script>

  
<script src="/blog/js/local-search.js"></script>






  





</body>
</html>
